const { BaseCommand } = require("./base");
const JavaScriptObfuscator = require("javascript-obfuscator");

class ObfuscateCommand extends BaseCommand {
    async execute() {
        const PRESET_OPTIONS = {
            optionsPreset: "default",
            compact: true,
            selfDefending: false,
            disableConsoleOutput: false,
            debugProtection: false,
            debugProtectionInterval: 0,
            splitStrings: false,
            splitStringsChunkLength: 10,
            splitStringsChunkLengthEnabled: false,
            stringArray: true,
            stringArrayRotate: true,
            stringArrayRotateEnabled: true,
            stringArrayShuffle: true,
            stringArrayShuffleEnabled: true,
            simplify: true,
            stringArrayThreshold: 0.75,
            stringArrayThresholdEnabled: true,
            stringArrayIndexesType: ["hexadecimal-number"],
            stringArrayIndexShift: true,
            stringArrayCallsTransform: false,
            stringArrayCallsTransformThreshold: 0.5,
            stringArrayEncoding: ["none"],
            stringArrayEncodingEnabled: true,
            stringArrayWrappersCount: 1,
            stringArrayWrappersChainedCalls: true,
            stringArrayWrappersParametersMaxCount: 2,
            stringArrayWrappersType: "variable",
            numbersToExpressions: false,
            sourceMap: false,
            sourceMapBaseUrl: "",
            sourceMapFileName: "",
            domainLock: [],
            domainLockRedirectUrl: "about:blank",
            domainLockEnabled: true,
            forceTransformStrings: [],
            reservedNames: [],
            reservedStrings: [],
            seed: 0,
            controlFlowFlatteningThreshold: 0.75,
            controlFlowFlattening: false,
            deadCodeInjectionThreshold: 0.4,
            deadCodeInjection: false,
            unicodeEscapeSequence: false,
            renameGlobals: false,
            renameProperties: false,
            renamePropertiesMode: "safe",
            target: "browser",
            identifierNamesGenerator: "hexadecimal",
            identifiersDictionary: [],
            identifiersPrefix: "",
            transformObjectKeys: false,
            ignoreImports: false,
        };
        const options = {
            ...PRESET_OPTIONS,
            ...this.selfData.options,
        };
        const result = JavaScriptObfuscator.obfuscate(this.content, options);
        return result.getObfuscatedCode();
    }

    getRequireContent() {
        return true;
    }
}

module.exports = {
    ObfuscateCommand,
};
